#Simple http connection libary for twirex based on python's urllib
import urllib

def post_grr(url, function, tags, email, password, grr):
    """
    Usage example: post('http://twirex.com/','api-post-message','shdhmc,6','mail@example.com','pwrd','hola')
    """
    appid = 'Grr-It'
    content = urllib.urlencode({
                                                'email':email,
                                                'password':password,
                                                'message':grr
                                                })
    params = urllib.urlencode({
        'from': appid,
        'tags': tags
    })
    path = url +function+'?'+ params
    response = urllib.urlopen(path,content).read()
    print response
    return response


def post(url, function,postParamsDict,getParamsDict=None):
    content = urllib.urlencode(postParamsDict)
    
    path = url + function
    if getParamsDict:
        params = urllib.urlencode(getParamsDict)
        path+='?'+ params
    response = urllib.urlopen(path,content).read()
    return response

def get(url,function, paramsDict):
    params= urllib.urlencode(paramsDict)
    path = url +function+'?'+ params
    response = urllib.urlopen(path).read()
    return response